package com.ibm.db2oncampus.portal.util;

import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletResponse;

/**
 * 
 * @author eberton.consolim
 *
 */

public class JSFUtil {
	
	public static ServletResponse getServletResponse(){
		return (ServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
	}

	public static FacesContext getCurrentInstance() {
		return FacesContext.getCurrentInstance();
	}
	
	public static ExternalContext getExternalContext() {
		return getCurrentInstance().getExternalContext();
	}
	
	public static String getRequestParameter(String parameterName) {
	    Map paramMap = getExternalContext().getRequestParameterMap();
	    return (String) paramMap.get(parameterName);
	}
	
	public static void setRequestParameter(String name, Object value) {
		Map paraMap = getExternalContext().getRequestMap();
		paraMap.put(name, value);
	}
	
	public static void addGlobalMessage(String message) {
	    FacesMessage facesMessage = new FacesMessage(message);
	    FacesContext.getCurrentInstance().addMessage(null, facesMessage);    
	}	
}
